package pl.edu.utp.kursy.database.dao;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import pl.edu.utp.kursy.database.Inovice;

public class InoviceDao extends BaseDao<Inovice>{
    
    public InoviceDao(SessionFactory sessionFactory){
        super(sessionFactory);
    }
    
    @Override
    public Inovice getById(int id) {
        Session session = sessionFactory.openSession();
        Criteria c = session.createCriteria(Inovice.class);
        c.add(Restrictions.eq("id", id));    		    		
        Inovice inovice = (Inovice)c.uniqueResult();
        session.close(); 
        return inovice; 
    }

    @Override
    public List<Inovice> getAll() {
        ArrayList<Inovice> inovices;
        Session session = sessionFactory.openSession();
        Criteria c = session.createCriteria(Inovice.class);
        c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        inovices = (ArrayList<Inovice>)c.list();
        session.close();
        return inovices;  
    }   
}